package com.anXin.user.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.anXin.model.common.dtos.ResponseResult;
import com.anXin.model.common.enums.AppHttpCodeEnum;
import com.anXin.model.user.pojos.UserFan;
import com.anXin.user.mapper.UserFanMapper;
import com.anXin.user.service.UserFanService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import utils.thread.AppThreadLocalUtil;


@Service("userFanService")
public class UserFanServiceImpl extends ServiceImpl<UserFanMapper, UserFan> implements UserFanService {


    @Override
    public ResponseResult isFan(Long userId) {
        UserFan one = query().eq("user_id", AppThreadLocalUtil.getUser().getId()).eq("fans_id", userId).one();
        if (ObjectUtil.isEmpty(one))return ResponseResult.errorResult(AppHttpCodeEnum.DATA_LIST_NULL);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    @Override
    public ResponseResult fanList(Long userId) {
        List<UserFan> userFans = query().eq("user_id", userId).list();
        if (userFans.isEmpty())return ResponseResult.errorResult(AppHttpCodeEnum.DATA_LIST_NULL);
        return ResponseResult.okResult(userFans);
    }

    @Override
    public Integer fansCount(Long userId) {

        return query().eq("user_id", userId).count();
    }
}